﻿var status = 0;
var bossid = "等级礼包";
var giftLevel = Array(10,30,60,100,160,180,200,210,220,230,240,250);
var giftContent = Array(
        //10
	Array(4001713, 5, 1), // 定居金10W

	//30
   Array(1102590, 1, 2),// 艾利涅的翅膀
	Array(1082533, 1, 2), // 艾利涅的手镯


	//60
   Array(2000005, 300, 3),// 超级药水
	Array(1132292, 1, 3), //水手腰带
	Array(1012389, 1, 3),//水手面罩
	Array(1022114, 1, 3),//米卡埃尔的眼镜


	//100级
    Array(4001714, 3, 4),// 定居金100万
	Array(1003364, 1, 4),//传说冒险岛帽子
	Array(1052405, 1, 4),//传说冒险岛套服	
	Array(1072610, 1, 4),//传说冒险岛靴子	
	Array(1082391, 1, 4),//传说冒险岛手套	
	Array(1102322, 1, 4),//传说冒险岛披风		
	Array(1132110,1, 4),//传说冒险岛腰带	
	Array(1152068,1, 4),//传说冒险岛护肩
	Array(2614040,5, 4),//突破五十万之石 100%




	//160
	Array(4001714, 1, 5),//定居金100W
	Array(2430483, 1, 5), //145武器自选
	Array(2049025, 5, 5), //白医卷轴
	Array(4001714, 1, 5),// 定居金100万
	Array(2614040,5, 5),//突破五十万之石 100%	



	//180
	Array(1662000, 1, 6),//普及型智能机器人(男)
	Array(1662001, 1, 6), //普及型智能机器人(女)
	Array(1672012, 1, 6), //永恒的钢铁心脏	
	Array(4001714, 1, 6),// 定居金100万
	Array(2614040,5, 6),//突破五十万之石 100%	




	//200
	Array(1102887, 1, 7),//缘分之翼
	Array(2049402, 5, 7), //特殊潜能附加卷轴
	Array(2614024, 5, 7), //突破百万之石 50%





	//210
	Array(2340000, 10, 8), //祝福卷轴
	Array(2049116, 10, 8), //强化混沌卷轴
	Array(2049603, 3, 8), //还原卷轴
	Array(2614024, 10, 8), //突破百万之石 50%

	//220
	Array(5062010, 5, 9), //终极神奇魔方
	Array(5062024, 5, 9), //闪炫魔方
	Array(5062500, 5, 9), //大师附加神奇魔方
	Array(2614024, 15, 9), //突破百万之石 50%

	//230
	Array(5062010, 10, 10), //终极神奇魔方
	Array(5062024, 10, 10), //闪炫魔方
	Array(5062500, 10, 10), //大师附加神奇魔方
	Array(2614024, 20, 10), //突破百万之石 50%
	
	
	
	//240
	Array(5062010, 15, 11), //终极神奇魔方
	Array(5062024, 15, 11), //闪炫魔方
	Array(5062500, 15, 11), //大师附加神奇魔方
	Array(2614024, 25, 11), //突破百万之石 50%



	//250
	Array(5062010, 20, 12), //终极神奇魔方
	Array(5062024, 20, 12), //闪炫魔方
	Array(2614024, 30, 12), //突破百万之石 50%
	Array(5062500, 20, 12) //大师附加神奇魔方




)
var giftId = -1;
var giftToken = Array();
var gifts = null;
function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (status == 0 && mode == 0) {
        cm.dispose();
        return;
    }
    if (mode == 1) {
        status++;
    } else {
        status--;
    }
    var job = cm.getJob();
    if (job == 10000 || job == 10100 || job == 10110 || job == 10111 || job == 10112) {
    	giftLevel = Array(110,120,130,140,160,180,200,210,220,230,240,250);
    }
    if (status == 0) {
		var text = "";
		text += "嘿，我为你准备了许多宝贝，等你达到相应等级的时候就可以领取了，另外点击可以查看礼包内容呢，快抢先看看吧！\r\n";
		for(var key in giftLevel) {
			var tips = "";
			giftToken[key]=false;
			if (cm.getChar().getLevel()>=giftLevel[key]) {
				if (cm.getBossLog(bossid+key) >= 0) {
					tips = "(可领取)";
					giftToken[key]=true;
				} else {
					tips = "#g(已领取)#b";
				}
			} else {
				tips = "#r(等级不足)#b";
			}
			text+="#b#L"+(parseInt(key)+1)+"#领取#r#e"+giftLevel[key]+"#n#b级等级礼包 "+tips+"#l#k\r\n";
		}
		cm.sendSimple(text);
	} else if (status == 1) {
		giftId = parseInt(selection);
		var text="#r#e"+giftLevel[giftId-1]+"#n#b级礼包内容：\r\n";
		gifts = getGift(giftId);
		for(var key in gifts) {
			var itemId = gifts[key][0];
			var itemQuantity = gifts[key][1];
			text+="#v"+itemId+"##b#t"+itemId+"##k #rx "+itemQuantity+"#k\r\n";
		}
		text+="\r\n#d是否现在就领取该礼包？#k";
		cm.sendYesNo(text);
	} else if (status == 2) {
		if (giftId!=-1 && gifts != null) {
			/*if (cm.getSpace(1) < 8 || cm.getSpace(2) < 8 || cm.getSpace(3) < 8 || cm.getSpace(4) < 8 || cm.getSpace(5) < 8) {
				cm.sendOk("您的背包空间不足，请保证每个栏位至少8格的空间，以避免领取失败。");
				cm.dispose();
				return ;
			}*/
			if (giftToken[giftId-1]) {
				cm.setBossLog(bossid+(giftId-1),0,-2);
				for(var key in gifts) {
					var itemId = gifts[key][0];
					var itemQuantity = gifts[key][1];
					cm.gainItem(itemId, itemQuantity);
				}
				cm.sendOk("恭喜您，领取成功！快打开包裹看看吧！");
				cm.dispose();
			} else {
				status = -1;
				cm.sendSimple("您已经领过了该礼包或者等级未达到要求，无法领取。");
			}
		} else {
			cm.sendOk("领取错误！请联系管理员！");
			cm.dispose();
		}
	}
}
function getGift(id) {
	var lastGiftContent = Array();
	for (var key in giftContent) {
		if (giftContent[key][2]==id)
			lastGiftContent.push(giftContent[key]);
	}
	return lastGiftContent;
}